import math

import numpy as np

from src.interpreter import bin2dec, dec2bin, bin2dec16, dec2bin16


def modify(tensor):
    tensor_str = dec2bin(tensor)
    tensor_str_lst = list(tensor_str)

    low_tensor = 0
    up_tensor = 0
    for i in range(len(tensor_str_lst)):
        new_tensor_lst = list(tensor_str_lst)
        new_tensor_lst[i] = str(1 - int(tensor_str_lst[i]))
        new_tensor = bin2dec(''.join(new_tensor_lst))
        if i == 0:
            low_tensor = up_tensor = new_tensor
        else:
            if low_tensor > new_tensor:
                low_tensor = new_tensor
            if up_tensor < new_tensor:
                up_tensor = new_tensor

    return low_tensor, up_tensor

import os
os.environ["CUDA_DEVICE_ORDER"] = "PCI_BUS_ID"
os.environ["CUDA_VISIBLE_DEVICES"] = "1"
import tensorflow as tf
import torch
if __name__ == '__main__':
    lst = [-8]
    print(lst)
    tensor = np.asarray(lst, dtype=np.float16)
    print(tf.nn.sigmoid(tensor))